home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 735 / 735.xpi / chrome / answers.jar / content / answers.js < prev    next >
Text File  |  2010-02-04  |  22KB  |  707 lines

  1. // Written by Asher Szmulewicz 06/06/2005 ashers@answers.com
  2. // ⌐ Copyright Answers Corporation 2005
  3. //  All rights reserved
  4.  
  5. // create the base ANSW object if it does not exist.
  6.  if (typeof ANSW=="undefined") {
  7.      ANSW = new Object();
  8.  }
  9. window.addEventListener(
  10.   "load",
  11.   function () {
  12.     // Add a callback to be run every time a document loads.
  13.     // note that this includes frames/iframes within the document
  14.     gBrowser.addEventListener("load", ANSW.initLoad, true);
  15.   },
  16.   false
  17. );
  18.  
  19. ANSW.pointedWords = "";
  20. ANSW.fw = 0;
  21. ANSW.fc = 0;
  22. ANSW.fc_set = false;
  23. ANSW.leftbuttondown = false;
  24. ANSW.rightbuttondown = false;
  25. ANSW.modKey=ANSW.modifierKey.get();
  26. ANSW.tabSelected = function(ev)
  27. {
  28.   if (ANSW.b5)
  29.   {
  30.       ANSW.b5.Hide();
  31.       delete ANSW.b5;
  32.   }
  33.   ANSW.b5 = new ANSW.Balloon();
  34.   ANSW.b5.isFirefox=true; //because of Shiretoko
  35.   ANSW.b5.initBalloon({width:490,autoAway:false});
  36.   ANSW.doc= content.document;
  37.   document.addEventListener("keyup",ANSW.b5.onkeyup,false);
  38.  
  39. };
  40. ANSW.isFirefoxExtension = true;
  41. ANSW.initLoad = function(ev) 
  42. {
  43.   gBrowser.mTabContainer.addEventListener("select", ANSW.tabSelected, false);
  44.   var menu = document.getElementById("contentAreaContextMenu");
  45.   if (menu!=null)
  46.     menu.addEventListener("popupshowing", ANSW.contextShowing, false);
  47.   document.addEventListener("click", ANSW.onClick, true);
  48.   document.addEventListener("mouseup",ANSW.getWordFromEvent ,true);
  49.   document.addEventListener("mousedown",ANSW.onMouseDown ,true);
  50.   document.addEventListener("contextmenu",ANSW.rightClick,true);
  51. //  document.addEventListener("unload", ANSW.unloadOverlay, false);
  52.   var myserver = "";    
  53.   var preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("answers.");
  54.   if (ANSW.version=="1.0") // from webtip1.js
  55.   {
  56.     ANSW.version="2.3.53"
  57.     ANSW.setStringPreference("version",ANSW.version);
  58.   }
  59.   if (preferencesService.prefHasUserValue("server.name"))
  60.         myserver = preferencesService.getCharPref("server.name");
  61.   if (myserver.length>0)
  62.         ANSW.server = myserver;
  63.   if (ev.originalTarget.location==content.document.location)
  64.   {
  65.       if (ANSW.b5)
  66.       {
  67.           ANSW.b5.Hide();
  68.           delete ANSW.b5;
  69.       }
  70.       ANSW.b5 = new ANSW.Balloon();
  71.       ANSW.b5.isFirefox=true; //because of Shiretoko
  72.       ANSW.b5.initBalloon({width:490,autoAway:false});
  73.       ANSW.doc = null;
  74.       
  75.   }
  76.   document.addEventListener("keyup",ANSW.b5.onkeyup,false);
  77. };
  78. ANSW.onMouseDown = function(ev)
  79. {
  80.   if (ev[ANSW.modKey] == true)
  81.   {
  82.       var altleftclick = true;
  83.       var preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("answers.");
  84.       if(preferencesService.prefHasUserValue("action.altclick"))
  85.          altleftclick = preferencesService.getBoolPref("action.altclick");
  86.       if (ev.which == 3  || (ev.which == 1 && altleftclick == true)) // right click or left click
  87.       {
  88.           if (ANSW.modKey=="ctrlKey")
  89.             ANSW.rightbuttondown = true;
  90.         ev.preventDefault(); 
  91.         ev.stopPropagation();
  92.         return false;
  93.       }
  94.   }
  95.   else
  96.   {
  97.     if(ANSW.b5.isVisible())
  98.     {
  99.         var el = ev.originalTarget;
  100.         if (el.id && el.id=="AnswersCloseImage")
  101.             return true;
  102.         if (ev.which==3)
  103.         {
  104.             var elem = ANSW.b5.getReal(el);
  105.             if (elem.id == "AnswersBalloon")
  106.             {
  107.                 ev.preventDefault();
  108.                 ev.stopPropagation();
  109.                 return false;
  110.             }
  111.             return true;
  112.         }
  113.        ANSW.b5.checkDown(ev,el);
  114.     }
  115.   }
  116.   return true;
  117. };
  118. ANSW.contextShowing = function() 
  119. {
  120.   var menuitem = document.getElementById("oneclick-answers");
  121.   if (gContextMenu.isTextSelected) 
  122.   {
  123.       var text;
  124.       if (gContextMenu.searchSelected)
  125.             text = gContextMenu.searchSelected();
  126.         else
  127.             text = getBrowserSelection();
  128.       if (text.length > 15) 
  129.         text = text.substr(0,15) + "...";
  130.       var displaytext = "Look up \"" + text + "\" on Answers.com";
  131.       menuitem.setAttribute("label", displaytext);
  132.       menuitem.setAttribute("hidden","false");
  133.   }
  134.   else 
  135.   {
  136.       var displaytext = "Look up on Answers.com";
  137.       menuitem.setAttribute("label", displaytext);
  138.       menuitem.setAttribute("hidden","false");
  139.   }
  140. };
  141. ANSW.openLink = function(lnk,ev) 
  142. {
  143.       action = ANSW.getOptionAction();
  144.     var browser = getBrowser();
  145.     var ctrlKey = false;
  146.     var shiftKey = false;
  147.     if (ev != null)
  148.     {
  149.         ctrlKey = ev.ctrlKey;
  150.         shiftKey = ev.shiftKey;
  151.         if (ctrlKey == true)
  152.             action = 3;
  153.         else if (shiftKey == true)
  154.             action = 2;
  155.         else 
  156.             action = 1;
  157.     }
  158.     if (action == 3) 
  159.     {
  160.           var newTab = browser.addTab(lnk);
  161.       browser.selectedTab = newTab;
  162.     } 
  163.     else if (action == 1) 
  164.     {
  165.             window.loadURI(lnk);
  166.     } else /*if (action == 2) */
  167.     {
  168.             window.open(lnk);
  169.     }
  170. };
  171. ANSW.getOptionAction = function()
  172. {
  173.   var myserver = "";    
  174.   var prefs = Components.classes["@mozilla.org/preferences-service;1"].
  175.                 getService(Components.interfaces.nsIPrefBranch);
  176.   if (ANSW.getFirefoxVersion()< 3)
  177.       return prefs.getIntPref("browser.link.open_external");
  178.   else
  179.       return prefs.getIntPref("browser.link.open_newwindow");
  180. };
  181.  
  182. ANSW.lookup = function()
  183. {
  184.     var text = "";
  185.     var focusword = false;
  186.     if (gContextMenu.onTextInput) 
  187.     {
  188.         text = document.popupNode;
  189.         text = text.value.substring(text.selectionStart, text.selectionEnd);
  190.         if (text.length>80) 
  191.             text = text.substr(0,79);
  192.     }      
  193.     else 
  194.     {
  195.         if (gContextMenu.searchSelected)
  196.             text = gContextMenu.searchSelected();
  197.         else
  198.             text = getBrowserSelection();
  199.         if (text.length == 0)
  200.         {
  201.             focusword = true;
  202.             text = ANSW.pointedWords;
  203.         }
  204.         else if (text.length>80)
  205.             text = text.substr(0,79);
  206.     }
  207.     if (text.length>0)
  208.     {
  209.         // urlify and encode utf8 the search string
  210.         var search = encodeURIComponent(text);
  211.           var URL = "http://" + ANSW.server + "/main/ntquery?s=" + search;
  212.         if (focusword)
  213.         {
  214.             URL += "&fw=" + ANSW.fw ;
  215.             URL += "&fc=" + ANSW.fc ;
  216.         }
  217.         URL +="&gwp=16";
  218.         ANSW.openLink(URL,null);
  219.     }
  220.     // re init
  221.     ANSW.pointedWords=""; 
  222.     ANSW.fw=0;
  223.     ANSW.fc=0;
  224. };
  225. ANSW.onClick = function(ev)
  226. {
  227.     var altleftclick = true;
  228.     var  preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("answers.");
  229.     if(preferencesService.prefHasUserValue("action.altclick"))
  230.         altleftclick = preferencesService.getBoolPref("action.altclick");
  231.     if(ev.button == 0 && ev[ANSW.modKey] == true && altleftclick == true)
  232.     {
  233.             ev.stopPropagation();
  234.             ev.preventDefault(); 
  235.             return false;
  236.     }
  237.     if(ev.button == 2 && ev[ANSW.modKey] == true)
  238.     {
  239.             ev.stopPropagation();
  240.             ev.preventDefault(); 
  241.             return false;
  242.     }
  243.     return true;
  244. };
  245.  
  246. ANSW.getWordFromEvent = function(ev) 
  247. {
  248.     ANSW.b5.moveme_onmouseup();
  249.     if (ev[ANSW.modKey] == true) // alt-pressed
  250.     {
  251.         // re init
  252.         ANSW.pointedWords=""; 
  253.         ANSW.fw=0;
  254.         ANSW.fc=0;
  255.         var altleftclick = true;
  256.         var answertip = true;
  257.         var preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("answers.");
  258.         if(preferencesService.prefHasUserValue("action.altclick"))
  259.             altleftclick = preferencesService.getBoolPref("action.altclick");
  260.         if(preferencesService.prefHasUserValue("view.answertip"))
  261.             answertip = preferencesService.getBoolPref("view.answertip");
  262.         if (ev.which == 3  || (ev.which == 1 && altleftclick == true)) // right click or left click
  263.         {
  264.             ev.stopPropagation();
  265.             ev.preventDefault(); 
  266.             
  267.             var range = document.createRange();
  268.             var initialNode = ev.rangeParent;
  269.             range.selectNode(ev.rangeParent);
  270.             var rangeOffset = ev.rangeOffset;
  271.             var netmask_term= ev.originalTarget.getAttribute("netmask_term");
  272.             var rngstr=range.toString();
  273.             if (ANSW.trim(rngstr).length==0)
  274.                 return;   // empty string  return
  275.             var fclist = rngstr.split(/\s+/);
  276.             var list_length=fclist.length;
  277.             ANSW.fc=rangeOffset;
  278.             var fword=fclist.shift();
  279.             var fw_pos=0; //  focus word position
  280.             var originalText=ANSW.fw;
  281.             while (ANSW.fc>fword.length && fword.length>0)
  282.             {
  283.                 ANSW.fc-=fword.length+1;
  284.                 fword=fclist.shift();
  285.                 fw_pos++;
  286.             }
  287.             fw_pos++;
  288.             if(ANSW.fc>0)
  289.                 ANSW.fc--; // zero based but don't want -1 happens sometimes
  290.             if (list_length-fw_pos<3 || fw_pos<3) // less than 3 words around the focus word
  291.             {
  292.                 var rootnode=initialNode.parentNode.parentNode?initialNode.parentNode.parentNode:initialNode.parentNode;
  293.                 if (netmask_term!=null && netmask_term!="" && rootnode.parentNode)
  294.                      rootnode=rootnode.parentNode.parentNode?rootnode.parentNode.parentNode:rootnode.parentNode;
  295.                 var walker=document.createTreeWalker(rootnode, NodeFilter.SHOW_TEXT, null, false)
  296.                 walker.currentNode = initialNode
  297.                 var origText = walker.currentNode.nodeValue
  298.                 var paratext = "";
  299.                 var textList=origText.split(/\s+/);
  300.                 while (walker.previousSibling() && textList.length<5){ //Step through each previous sibling
  301.                     paratext=walker.currentNode.nodeValue+paratext
  302.                     textList=paratext.split(/\s+/);
  303.                 }
  304.                 // add original text
  305.                 rangeOffset+= paratext.length;
  306.                 paratext+=origText
  307.                 textList=paratext.split(/\s+/);
  308.                 var origWord=textList.pop();
  309.                 if (netmask_term!=null && netmask_term!="" && origWord!=originalText)
  310.                 {
  311.                     if (origWord.length>originalText.length)
  312.                         ANSW.fc +=origWord.length+1-originalText.length;
  313.                     else
  314.                         textList.push(origWord);
  315.                 }
  316.                 else
  317.                     textList.push(origWord);
  318.                 var wordNumber= textList.length;
  319.                 // go back to middle
  320.                 walker.currentNode = initialNode
  321.                 while (walker.nextSibling() && textList.length<wordNumber+5){ //Step through each next sibling
  322.                     paratext+=walker.currentNode.nodeValue
  323.                     textList=paratext.split(/\s+/);
  324.                 }
  325.                 rngstr=paratext;
  326.             }
  327.             range.detach();
  328.             // remove leading white space
  329.             var nonWS = rngstr.search(/\S/);
  330.             rngstr = rngstr.substr(nonWS).replace(/(\r|\n)/, " ");
  331.             rangeOffset -= nonWS;
  332.             // which word is the focus word - i.e. which word the rangeOffset is in
  333.             var startstr = rngstr.substring(0, rangeOffset);
  334.             var endstr = rngstr.substring(rangeOffset, rngstr.length);
  335.             var wordlist = startstr.split(/\s+/);
  336.             var wordlist2 = endstr.split(/\s+/);
  337.             if (wordlist.length > 4)
  338.                 wordlist = wordlist.slice(wordlist.length-4);
  339.             if (wordlist2.length > 5)
  340.                 wordlist2 = wordlist2.slice(0, 4);
  341.             rngstr = wordlist.join(" ") + wordlist2.join(" ");
  342.             iStartWord = wordlist.length - 1;
  343.             var text = rngstr;
  344.             ANSW.fw=iStartWord;
  345.             if (text.length>80) 
  346.                 text = text.substr(0,79);
  347.             if (text.length>0)
  348.             {
  349.                 if (answertip == true)
  350.                 {
  351.                     ANSW.leftbuttondown = true;
  352.                     var el = ev.originalTarget;
  353.                     var elem = ANSW.getLastParent(el);
  354.                     var top = ev.pageY ;
  355.                     var left = ev.pageX ;
  356.                     var ad = content.document.getElementsByTagName("IFRAME");
  357.                     if (ad.length>0) // IFRAMES
  358.                     {
  359.                         var tmp =el;
  360.                         while (tmp != null && tmp.nodeType != 9)
  361.                         {
  362.                             tmp = tmp.parentNode;
  363.                         }
  364.                         for(var i=0;i<ad.length;i++)
  365.                         {
  366.                             if (tmp.location==ad[i].src)
  367.                             {
  368.                                 var temp= ad[i];
  369.                                 var offsetTop = 0;
  370.                                 var offsetLeft = 0;
  371.                                 while(temp)
  372.                                 {
  373.                                     offsetTop += temp.offsetTop;
  374.                                     offsetLeft += temp.offsetLeft;
  375.                                     temp=temp.offsetParent;
  376.                                 }
  377.                                 top +=offsetTop;
  378.                                 left += offsetLeft;
  379.                             }
  380.                         }
  381.                     }
  382.                     if (elem!=null && elem.tagName=="window")
  383.                     {
  384.                         ANSW.pointedWords=""; 
  385.                         ANSW.fw=0;
  386.                         ANSW.fc=0;
  387.                         ANSW.fc_set=false;
  388.                         return false;
  389.                     }
  390.                     if(ANSW.b5.isVisible())
  391.                     {
  392.                         elem = ANSW.b5.getReal(el);
  393.                         if (elem.id == "AnswersBalloon")
  394.                         {
  395.                             top = -1;
  396.                             left = -1;
  397.                         }
  398.                     }
  399.                     if (elem.nodeName!="BODY")
  400.                         elem = null;
  401.                     ANSW.b5.FireQuery(text,top,left,ANSW.fw,elem,null,null,ANSW.fc);
  402.                 }
  403.                 else
  404.                 {
  405.                 // urlify and encode utf8 the search string
  406.                     var search = encodeURIComponent(text);
  407.                     var URL = "http://" + ANSW.server + "/main/ntquery?s=" + search + "&fw=" + ANSW.fw + "&fc=" + ANSW.fc  +"&gwp=16";
  408.                     ANSW.openLink(URL,ev);
  409.                 }
  410.             }
  411.             // re init
  412.             ANSW.pointedWords=""; 
  413.             ANSW.fw=0;
  414.             ANSW.fc=0;
  415.             ANSW.fc_set=false;
  416.             return false;
  417.         }
  418.     }
  419.     else if (ev.which == 3)// right click
  420.     {
  421.         // re init
  422.         ANSW.pointedWords=""; 
  423.         ANSW.fw=0;
  424.         ANSW.fc=0;
  425.         ANSW.fc_set= false;
  426.         if(ANSW.b5.isVisible())
  427.         {
  428.             var el = ev.originalTarget;
  429.             var elem = ANSW.b5.getReal(el);
  430.             if (elem.id == "AnswersBalloon")
  431.             {
  432.                 ev.preventDefault();
  433.                 ev.stopPropagation();
  434.                 return false;
  435.             }
  436.         }
  437.  
  438.         var range = document.createRange();
  439.         range.setStart(ev.rangeParent, ev.rangeOffset);
  440.         range.setEnd(ev.rangeParent, ev.rangeOffset);
  441.         ANSW.expandRangeToWords(range,true,2,2);
  442.         range.detach();
  443.         return false;
  444.     }
  445.     return true;
  446. };
  447.  
  448. ANSW.expandRangeToWords = function(range,left2right,previous,next) 
  449. {
  450.   var startOfWord = /^\s\S+$/;
  451.   var endOfWord =  /^\S+\s$/;
  452.   var whitespace = /^\s+$/;
  453.   var dir = 1;
  454.   if (left2right == false)
  455.         dir = -1; // right to left
  456.   var i = 1;
  457.   var previous_at_start = previous;
  458.   var next_at_start = next;
  459.   
  460.   // if offset is inside whitespace
  461.   try
  462.   {
  463.     range.setStart(range.startContainer, range.startOffset - 1);
  464.   }
  465.   catch(e)
  466.   {
  467.     previous =0;
  468.     next = 0;
  469.     return;
  470.   }
  471.   if (range.toString().length == 0) // empty range
  472.         return;
  473.   while (whitespace.test(range.toString())) 
  474.   {
  475.       try
  476.       {
  477.         range.setEnd(range.endContainer, range.endOffset + dir);
  478.         range.setStart(range.startContainer, range.startOffset + dir);
  479.       }
  480.       catch(e)
  481.       {
  482.         previous =0;
  483.         next = 0;
  484.         return;
  485.       }
  486.   }
  487.   if (range.toString().length == 0) // empty range after whitespace
  488.         return;
  489.   var fc_end = 0;
  490.   while (!startOfWord.test(range.toString())) 
  491.   {
  492.     try
  493.     {
  494.         if (dir == 1 && ANSW.fc == 0)
  495.         {
  496.             ANSW.fc = range.startOffset;
  497.         }
  498.         range.setStart(range.startContainer, range.startOffset - 1);
  499.         if (ANSW.fc_set == false)
  500.         {
  501.             fc_end = range.startOffset;
  502.         }
  503.         if (range.startOffset == 0)
  504.         {
  505.             if (range.toString().charAt(0)=='\n') 
  506.             {
  507.                 if (previous==previous_at_start)
  508.                 {
  509.                     ANSW.fc_set = true;
  510.                     fc_end = 1;
  511.                     ANSW.fc -= fc_end;
  512.                 }
  513.                 range.setStart(range.startContainer, range.startOffset+1);
  514.             }
  515.             i=0;
  516.             previous = 0;
  517.             break;
  518.         }
  519.     }
  520.     catch(e)
  521.     {
  522.         i = 0;
  523.         previous = 0;
  524.         break;
  525.     }
  526.   }
  527.   if (range.toString().length == 0) // empty range after startOfWord
  528.         return;
  529.   if (dir == 1 && ANSW.fc_set == false)
  530.   {
  531.     ANSW.fc_set = true;
  532.     ANSW.fc -= fc_end;
  533.   }
  534.   if (i==1 && previous!=0 && next!=0)
  535.   {
  536.     ANSW.fw++;
  537.     previous--;
  538.     var prevrange = range.cloneRange();
  539.     prevrange.setEnd(prevrange.endContainer,range.startOffset);
  540.     ANSW.expandRangeToWords (prevrange,false,previous,next);
  541.     ANSW.pointedWords +=  " ";
  542.     prevrange.detach();
  543.   }
  544.   range.setStart(range.startContainer, range.startOffset + i);
  545.   while (!endOfWord.test(range.toString())) 
  546.   {
  547.         try
  548.         {
  549.             range.setEnd(range.endContainer, range.endOffset + 1);
  550.         }
  551.         catch(e)
  552.         {
  553.             ANSW.pointedWords += range.toString();
  554.             next = 0;
  555.             return;
  556.         }
  557.   }
  558.   range.setEnd(range.endContainer, range.endOffset - 1);
  559.   ANSW.pointedWords +=  range.toString();
  560.   if (left2right && next>0)
  561.   {
  562.         next--;
  563.         var nextrange = range.cloneRange();
  564.         ANSW.pointedWords +=  " ";
  565.         try
  566.         {
  567.             nextrange.setEnd(nextrange.endContainer,range.endOffset + 2);
  568.             nextrange.setStart(nextrange.startContainer,range.endOffset+1);
  569.         }
  570.         catch(e)
  571.         {
  572.             next = 0;
  573.             return;
  574.         }
  575.         ANSW.expandRangeToWords (nextrange,true,0,next);
  576.         ANSW.pointedWords +=  " ";
  577.         nextrange.detach();
  578.   }
  579. };
  580. /*ANSW.unloadOverlay =function () // from twoElls
  581. {
  582.     //Get various things needed to deal with RDF.
  583.     var RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  584.     var Container = Components.classes["@mozilla.org/rdf/container;1"].getService(Components.interfaces.nsIRDFContainer);
  585.     var extensionDS= Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager).datasource;
  586.     
  587.     //Get nodes and arc needed to figure out whether the given extension is slated to be uninstalled.
  588.     var root = RDFService.GetResource("urn:mozilla:extension:root");
  589.     var nameArc = RDFService.GetResource("http://www.mozilla.org/2004/em-rdf#name");
  590.     var toBeUninstalledArc = RDFService.GetResource("http://www.mozilla.org/2004/em-rdf#toBeUninstalled");
  591.     
  592.     Container.Init(extensionDS,root);
  593.     
  594.     //Now iterate over the elements to find the toBeUninstalled value for the extension in question 
  595.     var found = false;
  596.     var elements = Container.GetElements();
  597.     while (elements.hasMoreElements()) 
  598.     {
  599.         var element = elements.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
  600.         var name = "";
  601.         var toBeUninstalled = "";
  602.     
  603.         var target = extensionDS.GetTarget(element, nameArc ,true);
  604.         if (target) 
  605.         {
  606.             name = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  607.         }
  608.     
  609.         target = extensionDS.GetTarget(element, toBeUninstalledArc ,true);
  610.         if (target) 
  611.         {
  612.             toBeUninstalled=target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  613.         }
  614.     
  615.         //If we find the right value, set the found flag to true.
  616.         if (toBeUninstalled && (toBeUninstalled == "true") && (name == "Answers")) 
  617.         {
  618.             found = true;
  619.         }
  620.     }
  621.     //Ok, our extension is slated to be uninstalled, so do some more stuff.
  622.     if(found==true)
  623.     {
  624.         try
  625.         {
  626.             //Get the localstore datasource
  627.             var ds=new RDFDataSource("rdf:local-store");
  628.  
  629.             //Get the sidebar-box node.
  630.             var node=ds.getNode("chrome://browser/content/browser.xul#sidebar-box");
  631.             //Get that nodeÆs properties and remove all targets, which typically include "src," "width," and "sidebarcommand"
  632.             //Removing all properties apparently causes the node itself to be deleted, which is the result weÆre actually going for.
  633.             var properties=node.getProperties();
  634.             while(properties.hasMoreElements())
  635.             {
  636.                 prop=properties.getNext();
  637.                 var target = node.getTarget(prop.getValue());
  638.                 node.removeTarget(prop.getValue(),target);
  639.             }
  640.     
  641.             //Now save and refresh the datasource.
  642.             ds.save();
  643.             ds.refresh();
  644.  
  645.             // reset to default=true the Answers prefs
  646.             var preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  647.             if(preferencesService.prefHasUserValue("answers.action.altclick"))
  648.             {
  649.                 preferencesService.setBoolPref("answers.action.altclick", true);
  650.             }
  651.             if(preferencesService.prefHasUserValue("answers.view.answertip"))
  652.             {
  653.                 preferencesService.setBoolPref("answers.view.answertip", true);
  654.             }
  655.         }
  656.         catch(e)
  657.         {
  658.         }
  659.     }
  660. };*/
  661. ANSW.rightClick = function(ev)
  662. {
  663.     var el = ev.originalTarget;
  664.     var elem = ANSW.b5.getReal(el);
  665.     if (elem.id == "AnswersBalloon" || ANSW.rightbuttondown==true)
  666.     {
  667.         ANSW.rightbuttondown = false;
  668.         if (ANSW.modKey=="ctrlKey")
  669.         {
  670.             ev.preventDefault();
  671.             ev.stopPropagation();
  672.             return false;
  673.         }
  674.         return true;
  675.     }
  676.     return true;
  677. };
  678. ANSW.getLastParent = function(el) 
  679. {
  680.     var temp = el;
  681.     while ((temp != null) && (temp.tagName != "BODY") && (temp.tagName != "window"))
  682.     {
  683.         temp = temp.parentNode;
  684.     }
  685.     return temp;
  686. };
  687.  
  688. // Sets a string preference
  689. ANSW.setStringPreference = function(preference, value)
  690. {
  691.     var preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("answers.");
  692.     // If the preference is set
  693.     if(preference && preferencesService)
  694.     {
  695.         var supportsStringInterface = Components.interfaces.nsISupportsString;
  696.         var string                  = Components.classes["@mozilla.org/supports-string;1"].createInstance(supportsStringInterface);
  697.  
  698.         string.data = value;
  699.  
  700.         preferencesService.setComplexValue(preference, supportsStringInterface, string);
  701.     }
  702. };
  703. ANSW.getFirefoxVersion = function(){
  704.     var userAgent = navigator.userAgent.toLowerCase();
  705.     var index = userAgent.lastIndexOf("/")+1;
  706.     return index==0?0:userAgent.charAt(index); 
  707. };